package com.serviceImpl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dao.UrlFilterMapper;
import com.pojo.UrlFilter;
import com.service.IUrlFilterService;
import com.shiro.FilterChainDefinitionsService;

@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 5)
@Service("urlFilterService")
public class UrlFilterServiceImpl implements IUrlFilterService{
	@Resource
	private FilterChainDefinitionsService definitionService;
	@Resource
	private UrlFilterMapper urlFiltermapper;

	public UrlFilter createUrlFilter(UrlFilter urlFilter) {
		urlFiltermapper.addurlFilter(urlFilter);
		definitionService.reloadFilterChains();// 重新加载权限过滤链
		return urlFilter;
	}

	public void deleteUrlFilter(int urlFilterId) {
		urlFiltermapper.deleteurlFilter(urlFilterId);
		definitionService.reloadFilterChains();// 重新加载权限过滤链
	}

	public List<UrlFilter> getUrlFilters(int page, int groups) {
		return urlFiltermapper.getUrlFilters((page - 1) * groups, groups);
	}

	public List<UrlFilter> getUrlFilters() {
		return urlFiltermapper.geturlFilters();
	}

	public UrlFilter getUrlFilterByid(int urlFilterid) {
		return urlFiltermapper.getUrlFilterByid(urlFilterid);
	}

	public UrlFilter updateUrlFilter(UrlFilter urlFilter) {
		urlFiltermapper.updateUrlFilter(urlFilter);
		definitionService.reloadFilterChains();// 重新加载权限过滤链
		return urlFilter;
	}

	public void deleteUrlFilters(int urlFilterId) {
		urlFiltermapper.deleteurlFilter(urlFilterId);
		definitionService.reloadFilterChains();// 重新加载权限过滤链
	}

	public int getCounts() {
		return urlFiltermapper.getCount();
	}
}
